﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Historia.Formulaires
{
    /// <summary>
    /// Interaction logic for frmOptions.xaml
    /// </summary>
    public partial class frmOptions : Window
    {
        #region Constructor

        public frmOptions()
        {
            InitializeComponent();
        }

        #endregion

        #region Methods

        protected void LoadData() {
            List<string> fonts = new List<string>();
            List<Double> fontsSize = new List<double>() { 8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72};

            foreach (System.Drawing.FontFamily ff in System.Drawing.FontFamily.Families)
            {
                if (ff.IsStyleAvailable(System.Drawing.FontStyle.Regular))
                {
                    fonts.Add(ff.Name);
                }
            }

            this.cboChapterSummaryFont.ItemsSource = fonts;
            this.cboChapterSummaryFontSize.ItemsSource = fontsSize;
            this.cboSceneSummaryFont.ItemsSource = fonts;
            this.cboSceneSummaryFontSize.ItemsSource = fontsSize;
            this.cboSceneTextFont.ItemsSource = fonts;
            this.cboSceneTextFontSize.ItemsSource = fontsSize;
        }

        protected void DisplayData() {
            this.cboChapterSummaryFont.SelectedValue = Properties.Settings.Default.ChapterSummaryFont;
            this.cboChapterSummaryFontSize.SelectedValue = Properties.Settings.Default.ChapterSummaryFontSize;
            
            this.cboSceneSummaryFont.SelectedValue =Properties.Settings.Default.SceneSummaryFont;
            this.cboSceneSummaryFontSize.SelectedValue = Properties.Settings.Default.SceneSummaryFontSize;
            
            this.cboSceneTextFont.SelectedValue = Properties.Settings.Default.SceneTextFont;
            this.cboSceneTextFontSize.SelectedValue = Properties.Settings.Default.SceneTextFontSize;
        }

        #endregion

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                this.LoadData();
                this.DisplayData();
            }
            catch (Exception ex)
            {
                
                throw;
            }
        }

        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Properties.Settings.Default.ChapterSummaryFont = this.cboChapterSummaryFont.SelectedValue.ToString();
                //Properties.Settings.Default.ChapterSummaryFontSize = Convert.ToDouble(this.txtChapterSummaryFontSize.Text);
                Properties.Settings.Default.ChapterSummaryFontSize = (double)this.cboChapterSummaryFontSize.SelectedValue;

                Properties.Settings.Default.SceneSummaryFont = this.cboSceneSummaryFont.SelectedValue.ToString();
                //Properties.Settings.Default.SceneSummaryFontSize = Convert.ToDouble(this.txtSceneSummaryFontSize.Text);
                Properties.Settings.Default.SceneSummaryFontSize = (double)this.cboSceneSummaryFontSize.SelectedValue;

                Properties.Settings.Default.SceneTextFont = this.cboSceneTextFont.SelectedValue.ToString();
                //Properties.Settings.Default.SceneTextFontSize = Convert.ToDouble(this.txtSceneTextFontSize.Text);
                Properties.Settings.Default.SceneTextFontSize =(double)this.cboSceneTextFontSize.SelectedValue;
                Properties.Settings.Default.Save();

                this.Close();
            }
            catch (Exception ex)
            {
                
                throw;
            }
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                this.Close();
            }
            catch (Exception ex)
            {
                
                throw;
            }
        }
    }
}
